package com.baidu.process.chat.parser;

import com.alibaba.fastjson.JSONObject;
import com.baidu.process.chat.core.action.Actions;
import com.baidu.process.chat.core.web.bean.IMRequestServer;
import com.baidu.process.chat.core.web.bean.IMResponseResult;
import com.baidu.process.chat.parser.bean.QueryJsonStr;
import com.baidu.process.ngd.bean.NGDStartResBody;
import com.baidu.process.record.bean.DialogueRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:fangyuchao
 * @Description:
 * @Date: Create in 9:44 2022/11/7
 */
@Service
public class FirstParseNgdResult implements ResultPaser<NGDStartResBody> {
    private static final Logger logger= LoggerFactory.getLogger(FirstParseNgdResult.class);
    @Override
    public IMResponseResult parseResult(NGDStartResBody ngdStartResBody, IMRequestServer imRequestServer, DialogueRecord dialogueRecord) {
        NGDStartResBody.NGDStartData queryData=null;
        try{
            IMResponseResult imResponseResult = new IMResponseResult();
            queryData = ngdStartResBody.getData();
            Map<String,Object> welcomeMap= new HashMap<>();
            QueryJsonStr queryJsonStr = new QueryJsonStr();
            //首轮回复话术不再用欢迎语queryData.getWelcome()
            queryJsonStr.setAnswer("");
            queryJsonStr.setBot(Actions.DEFAULT.getCode());
            queryJsonStr.setSource(queryData.getSource());
            queryJsonStr.setSessionId(queryData.getSessionId());
            imResponseResult.setJsonString(JSONObject.toJSONString(queryJsonStr));
            imResponseResult.setReturnCode("200");
            imResponseResult.setReturnMessage("");
            return imResponseResult;
        }catch (Exception e){
            e.printStackTrace();
            logger.error("[sessionid:]{},ngd欢迎语处理异常",queryData.getSessionId());
        }
      return null;
    }
}
